<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title></title>
	<meta http-equiv="Content-type" content="text/html; charset=utf-8">
	<meta name="decorator" content="ani"/>
	<script src="${ctxStatic}/common/js/common.js"></script>
	<%@ include file="/webpage/include/bootstraptable.jsp"%>
	<%@include file="/webpage/include/treeview.jsp" %>
	<script src="https://cdn.bootcss.com/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js"></script>
	<script type="text/javascript">
$(document).ready(function() {
	
	$('#needAssignTable').bootstrapTable({
		 
		  //请求方法
               method: 'get',
             //类型json
             dataType: "json",
             //显示刷新按钮
             showRefresh: false,
             //显示切换手机试图按钮
             showToggle:false,
             //显示 内容列下拉框
  	       showColumns: false,
  	       //显示到处按钮
  	       showExport: false,
  	       //显示切换分页按钮
  	       showPaginationSwitch: false,
  	       //最低显示2行
  	       minimumCountColumns: 2,
             //是否显示行间隔色
             striped: true,
             //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）     
             cache: false,    
             //是否显示分页（*）  
             pagination: false,   
              //排序方式 
             sortOrder: "asc",  
             //初始化加载第一页，默认第一页
             	pageNumber:1,   
             //每页的记录行数（*）   
            pageSize: 10,  
             //可供选择的每页的行数（*）    
             pageList: [10, 25, 50, 100],
             //这个接口需要处理bootstrap table传递的固定参数,并返回特定格式的json数据  
             url:"${ctx}/sc/logisticsVehicle/findByLogisticsVehicleList",
             //默认值为 'limit',传给服务端的参数为：limit, offset, search, sort, order Else
             //queryParamsType:'',   
             ////查询参数,每次调用是会带上这个参数，可自定义                         
             queryParams : function(params) {
            	 var searchParam = $("#searchForm").serializeJSON();
                	searchParam.pageNo = params.limit === undefined? "1" :params.offset/params.limit+1;
                	searchParam.pageSize = params.limit === undefined? -1 : params.limit;
                	searchParam.orderBy = params.sort === undefined? "" : params.sort+ " "+  params.order;
                    return searchParam;
             },
             //分页方式：client客户端分页，server服务端分页（*）
             sidePagination: "server",
             contextMenuTrigger:"right",//pc端 按右键弹出菜单
             contextMenuTriggerMobile:"press",//手机端 弹出菜单，click：单击， press：长按。
             contextMenu: '#context-menu', 
			 clickToSelect: true,              
               onClickRow: function(row, $el){       	   
            	  /*  var rows =$("#needAssignTable").bootstrapTable('getSelections');
            	    if(rows.length>1){
            	    	for(var i=1;i<rows.length;i++){
            	    		if(rows[i].customerId!=rows[i-1].customerId){
            	    			$("#vehicleAmount").val(1);
            	            	   $("#vehicleAmount").attr("disabled",true);
            	    		}
            	    	}
            	    } */
               },
               columns: [{
		        checkbox: true		       
		    }
             ,{
   		        field: 'customerName',
   		        title: '项目',
   		        sortable: true	       
   		    }
			,{
		        field: 'serviceTypeName',
		        title: '类型',
		        sortable: true	       
		    }
			
			,{
		        field: 'minRepairDate',
		        title: '最早上报时间',
		        sortable: true	       
		    }
			,{
		        field: 'amount',
		        title: '数量',
		        sortable: true	       
		    }
			,{
		        field: '',
		        title: '植物详情',
		        sortable: true,	  
		        formatter: function (value, row, index) {
                    var html = "<a onclick='detail(" + row.customerId + ",&quot;" + row.serviceType + "&quot;)'>详情</a>";
                    return html;                            
                 }
		    }
			
		     ]
		
		});
 	$.ajax({
	    type : "post",
	    url : ctx+"/sys/dict/findLogisticsVehicleTypeList", 
	    success : function(data) {						    	
	    	var optionstring = "<option value=''>"+"--请选择--"+"</option>";  
	    	if(data!=null){
		    	for(var i=0;i<data.length;i++){
		    		 optionstring += "<option value=\"" + data[i].value+ "\">" +data[i].label+ "</option>";
		    	}
	    	}							    	
	    	$("#vehicleType").html(optionstring); 
	    }
}); 
 	
 	$.ajax({
	    type : "post",
	    url : ctx+"/sc/logisticsVehicle/findSjType", 
	    success : function(data) {						    	
	    	var optionstring = "<option value=''>"+"--请选择--"+"</option>";  
	    	if(data!=null){
		    	for(var i=0;i<data.length;i++){
		    		 optionstring += "<option value=\"" + data[i].id+ "\">" +data[i].name+ "</option>";
		    	}
	    	}							    	
	    	$("#workerId").html(optionstring); 
	    }
}); 

		$("#search").click("click", function() {// 绑定查询按扭
			  $('#erpResTable').bootstrapTable('refresh');
			});	
})

	
 
  
function reBack() {
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    parent.layer.close(index);//关闭页面
}
function getIdSelections() {
    return $.map($("#needAssignTable").bootstrapTable('getSelections'), function (row) {
        return row;
    });
}
function detail(customerId,serviceType) {
    layer.open({
        type: 2,
        title: '植物详情',
        maxmin: true, //开启最大化最小化按钮*!/
        shadeClose: true,
        scrollbar: false,
        area: ['80%', '80%'],
        content:ctx+"/sc/logisticsVehicle/detail?customerId="+customerId+"&serviceType="+serviceType
    });
} 
function finish(){
    var ids=getIdSelections();
    if(ids==null || ids==''){
    	jp.error('请选择需要生产的资源!');
    	return;
    }
	jp.confirm('确认生产完成吗，操作后不能恢复！', function(){
		$.ajax({
            url: "${ctx}/sc/stockout/completeProduction",
            type: "post",
            dataType:"JSON",
            data:{ids:ids.toString()},
            beforeSend: function () {
                index = layer.load(1, {
                    shade: [0.5, '#fff'] //0.1透明度的白色背景
                });
            },
            complete: function () {
                layer.close(index);
            },
            success: function (data) {

                if (data== "1") {
                    layer.alert('保存成功!', {icon: 1, closeBtn: 0}, function (index) {
                    	location.reload();
                    });
                }
            },
            error: function (e) {
                layer.alert('保存失败!', {
                    icon: 2,
                    title: "提示"
                });

            }
        });
      	   
	})
}
function create(){
	var vehicleType=$("#vehicleType").val();
	var vehicleAmount=$("#vehicleAmount").val();
	var workerAmount=$("#workerAmount").val();
	var deliveryDate=$("#assignDate").val();
	var workerPrice=$("#workerPrice").val();
	var vehiclePrice=$("#vehiclePrice").val();
	var workerId=$("#workerId").val();
	if(vehicleType == null || vehicleType==''){
		jp.error("请选择车辆!");
		return;
	}
	if(vehicleAmount == null || vehicleAmount==''){
		jp.error("请填写车次!");
		return;
	}
	if(workerAmount == null || workerAmount==''){
		jp.error("请填写工人数量!");
		return;
	}
	if(deliveryDate == null || deliveryDate==''){
		jp.error("请选择指派日期!");
		return;
	}
	if(workerPrice == null || workerPrice==''){
		jp.error("请填写工人费用!");
		return;
	}
	if(vehiclePrice == null || vehiclePrice==''){
		jp.error("请填写车辆费用!");
		return;
	} 
	if(workerId == null || workerId==''){
		jp.error("请填写派送司机!");
		return;
	}
	var rows =$("#needAssignTable").bootstrapTable('getSelections');
	var arr = new Array();
    if(rows.length==0){
    	jp.error('请选择项目!');
    	return;
    }
    else{
    	for(var i=0;i<rows.length;i++){
    		var logis = new Object();
    		logis.customerId=rows[i].customerId;
    		logis.serviceType=rows[i].serviceType;
    		arr.push(logis);
    	}
    }
	$.ajax({
        url: "${ctx}/sc/logisticsVehicle/save",
        type: "post",
        dataType:"JSON",
        data:{
        	vehicleType:vehicleType,
        	vehicleAmount:vehicleAmount,
    	 	workerAmount:workerAmount,
    	 	deliveryDate:deliveryDate,
    		 workerPrice:workerPrice,
    		vehiclePrice:vehiclePrice,
    		arr:JSON.stringify(arr),
    		workerId:workerId
        },
        beforeSend: function () {
            index = layer.load(1, {
                shade: [0.5, '#fff'] //0.1透明度的白色背景
            });
        },
        complete: function () {
            layer.close(index);
        },
        success: function (data) {

            if (data== "1") {
                layer.alert('保存成功!', {icon: 1, closeBtn: 0}, function (index) {
                	location.reload();
                });
            }
        },
        error: function (e) {
            layer.alert('保存失败!', {
                icon: 2,
                title: "提示"
            });

        }
    });
}
</script>
</head>
<body style="background-color: white;">
<div class="wrapper wrapper-content">
	<div class="panel panel-primary">
	
	<div class="panel-body">
	

	<!-- 表格 -->
	<table id="needAssignTable"   data-toolbar="#toolbar"></table>
</div>
</div>
	

</div>



<table class="table table-bordered">
		     <tbody>
		      <tr>
		         <td  class="width-15 active"><label class="pull-right"><font color="red">*</font> 车型:</label></td>
		         <td class="width-15" >
		         	<select id="vehicleType" class="form-control " cssClass="form-control required">
					<select>
				</td>
		         <td  class="width-15 active"><label class="pull-right"><font color="red">*</font> 车次:</label></td>
		         <td  class="width-15" ><input id="vehicleAmount" type="number" min="1" class="form-control "/></td>
		         <td  class="width-15 active"><label class="pull-right"><font color="red">*</font> 指派日期:</label></td>
		         <td  class="width-15" >
		         
		         <div style="position:relative;">
		         <input id="assignDate" type="text" class="form-control "/>
		         </div>		        
		         </td>
		      </tr>
		      <tr>
		         <td  class="width-15 active"><label class="pull-right"><font color="red">*</font> 工人数:</label></td>
		         <td class="width-15" >
		         	<input id="workerAmount" type="number" min="1" class="form-control "/>
				</td>
		         <td  class="width-15 active"><label class="pull-right"><font color="red">*</font> 工人费用:</label></td>
		         <td  class="width-15" ><input id="workerPrice" type="number" min="0" class="form-control "/></td>
		         <td  class="width-15 active"><label class="pull-right"><font color="red">*</font> 车辆费用:</label></td>
		         <td class="width-15" >
		         	<input id="vehiclePrice" type="number" min="0" class="form-control "/>
				</td>
		      </tr>
		      <tr>
		         <td  class="width-15 active"><label class="pull-right"><font color="red">*</font> 指派司机:</label></td>
		         <td class="width-15" >
		         	<select id="workerId" class="form-control " cssClass="form-control required">
					<select>
				</td>
		      
		      </tr>
		    </tbody>
		     <script type="text/javascript">
					$('#assignDate').datetimepicker({
			        format: 'YYYY-MM-DD',
			        locale: moment.locale('zh-cn')
			  	  });
				</script>
		  </table>
			


<!-- <div class="form-group">				
		<label class="col-sm-2 control-label" style="text-align: right;">车型：</label>
		<div class="col-sm-2">
			<select id="vehicleType" class="form-control " cssClass="form-control required">
				
			<select>
		</div>
		<label class="col-sm-2 control-label" style="text-align: right;">车次：</label>
		<div class="col-sm-2">
			<input id="vehicleAmount" type="number" min="1" class="form-control "/>
		</div>
		
		<label class="col-sm-2 control-label" style="text-align: right;">工人数：</label>
		<div class="col-sm-2">
			<input id="workerAmount" type="number" min="1" class="form-control "/>
		</div>
	</div>	
	<div class="form-group">				
		<label class="col-sm-2 control-label" style="text-align: right;">指派日期：</label>
		<div class="col-sm-2">
			<input id="assignDate" type="text" class="form-control "/>
		</div>
		<label class="col-sm-2 control-label" style="text-align: right;">工人费用：</label>
		<div class="col-sm-2">
			<input id="workerPrice" type="number" min="0" class="form-control "/>
		</div>
		<label class="col-sm-2 control-label" style="text-align: right;">车辆费用：</label>
		<div class="col-sm-2">
			<input id="vehiclePrice" type="number" min="0" class="form-control "/>
		</div>
		
		<script type="text/javascript">
				$('#assignDate').datetimepicker({
			        format: 'YYYY-MM-DD',
			        locale: moment.locale('zh-cn')
			    });
		</script>
	</div>	 -->
		
	<!-- <div align="right"><button onclick="create()" type="button" class="btn btn-success">提交</button></div>	 -->
</body>
<script type="text/javascript">
	
</script>
</html>